<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('打分数据')"/>
</head>
<style>
    .panel {
        margin-bottom: 0px;
        margin-top: 10px;
        box-shadow: 1px 1px 3px rgb(0 0 0 / 20%);
    }

    .card {
        display: flex;
    }

    .title {
        width: 100%;
        display: flex;
        font-size: 14px;
    }

    .box-title {
        font-weight: 900;
        color: #686B6D;
    }

</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="panel panel-info">
            <div class="panel-heading">
                <i class="fa fa-info-circle"></i> 员工信息
            </div>
            <div class="panel-body">
                <div class="card">
                    <div class="title">
                        <div class="box-title">姓名：</div>
                        <label id="examineeName"></label></div>
                    <div class="title">
                        <div class="box-title">工号：</div>
                        <label id="badge"></label></div>
                    <div class="title">
                        <div class="box-title">二级部门：</div>
                        <label id="deptName"></label></div>
                    <div class="title">
                        <div class="box-title">三级部门：</div>
                        <label id="tertiaryDeptName"></label></div>
                    <div class="title">
                        <div class="box-title">岗位：</div>
                        <label id="jobName"></label></div>
                    <div class="title">
                        <div class="box-title">年份：</div>
                        <label id="years"></label></div>
                    <div class="title">
                        <div class="box-title">月份：</div>
                        <label id="months"></label></div>
                </div>
            </div>
        </div>

        <form id="scoring-form">
            <input id="scoringId" name="scoringId" type="hidden" th:value="${scoringId}"/>
            <input id="type" name="type" type="hidden" value='acv_scoring_gd'/>
            <!-- <input id="years" name="years" type="hidden" th:value="${years}"/> -->
            <!-- <input id="months" name="months" type="hidden" th:value="${months}"/> -->
            <div class="select-list">
            </div>
        </form>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>

        <div class="col-sm-12 search-collapse" style="padding-top: 10px;">
            <from class="form form-horizontal m-t">
                <div class="form-group">
                    <label class="col-sm-3 control-label"><h4>总分:</h4></label>
                    <div class="col-sm-8">
                        <input class="form-control" id="totalScore" disabled="disabled" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label"><h4>备注:</h4></label>
                    <div class="col-sm-8">
                        <textarea class="form-control" disabled="disabled" id="remarksTotal"></textarea>
                    </div>
                </div>
            </from>
        </div>

    </div>

</div>


<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "acvScoringManage"
    document.getElementById('examineeName').innerHTML = [[${examineeObj.examineeName}]];
    document.getElementById('badge').innerHTML = [[${examineeObj.badge}]];
    document.getElementById('deptName').innerHTML = [[${examineeObj.deptName}]];
    document.getElementById('tertiaryDeptName').innerHTML = [[${examineeObj.tertiaryDeptName}]];
    document.getElementById('jobName').innerHTML = [[${examineeObj.jobName}]];
    document.getElementById('years').innerHTML = [[${years}]];
    document.getElementById('months').innerHTML = [[${months}]];
    $(function () {
        $("#totalScore").val([[${scoreTotal}]]);
        $("#remarksTotal").val([[${remarksTotal}]]);

        var options = {
            code: "userId",
            uniqueId: "userId",
            url: prefix + "/scoringListByScoringId",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "用户",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            columns: [
                {
                    field: 'assessmentIndex',
                    title: '考核指标',
                    width: "10%"
                },
                {
                    field: 'describe',
                    title: '考核描述',
                    width: "30%"
                },
                {
                    field: 'goal',
                    title: '达成目标',
                    width: "20%"
                },
                {
                    field: 'standard',
                    title: '评分标准',
                    width: "20%"
                },
                {
                    field: 'distribution',
                    title: '指标配分'
                },
                {
                    title: '实际得分',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var score = row.score;
                        var id = row.templateId + 'ss';
                        actions.push('<input type="text" id="' + id + '" class="form-control" disabled="disabled" id="score" name="score" autocomplete="off" onkeyup="value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,1})?).*$/g, \'$1\')" value="' + score + '" />');
                        return actions.join('');
                    },
                    footerFormatter: function (value) {
                        return "总金额";
                    }
                },
                {
                    title: '备注',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var remarks = row.remarks;
                        var id = row.templateId + 'rr';
                        actions.push('<input type="text" id="' + id + '" autocomplete="off" disabled="disabled" class="form-control" id="remarks" name="remarks" value="' + remarks + '" />');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function getTotalScore() {
        var totalScore = 0;
        var data = $("#" + table.options.id).bootstrapTable('getData');
        for (var i = 0; i < data.length; i++) {
            totalScore += Number($("#" + data[i].templateId + "ss").val());
        }
        return totalScore;
    }

    function dataSave() {
        $.modal.confirm("确认要保存吗?", function () {
            var data = $("#" + table.options.id).bootstrapTable('getData');
            var scoringId = $("#scoringId").val();
            var scoreArray = new Array();
            for (var i = 0; i < data.length; i++) {
                var score = new Object();
                score.templateId = data[i].templateId;
                score.score = $("#" + data[i].templateId + "ss").val();
                if (score.score == "") {
                    $.modal.alertWarning('存在未打分项,请核实！');
                    return false;
                } else if (parseInt(score.score) > parseInt(data[i].distribution) && assessmentIndex.indexOf("其他加减分项目") == -1 && parseInt(data[i].distribution) > 0) {
                    $.modal.alertWarning('实际得分不得大于指标配分!');
                    return false;
                }
                score.remarks = $("#" + data[i].templateId + "rr").val();
                if (score.remarks == "") {
                    $.modal.alertWarning('请填写备注或填写[无]！');
                    return false;
                }
                scoreArray.push(score);
            }
            var totalScore = getTotalScore();
            $.ajax({
                type: "post",
                url: prefix + "/dataSave",
                data: {
                    "scoreArray": JSON.stringify(scoreArray),
                    "totalScore": totalScore,
                    "scoringId": scoringId,
                    "remarksTotal": $("#remarksTotal").val()
                },
                success: function (data) {
                    if (data.code == 0) {
                        $.table.search();
                        window.opener.location.reload();
                        $("#totalScore").val(totalScore);
                        $.modal.confirm("保存成功,是否关闭该页面?", function () {
                            window.close();
                        });
                    }
                }
            });
        });
    }

    function submitHandler() {
        dataSave();
    }


</script>
</body>
</html>